package 强化训练;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
//已通过
public class day41Emacs计算器 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String n = sc.nextLine();
            String s = sc.nextLine();
            String[] wd = s.split(" ");
            Deque<String> queue = new ArrayDeque<String>();
            for(int i =0; i < wd.length;i++){
                if("*".equals(wd[i])){
                    int num1 = Integer.parseInt(queue.pop());
                    int num2 = Integer.parseInt(queue.pop());
                    int res = num1 * num2;
                    queue.push(String.valueOf(res));
                }else if( "/".equals(wd[i]) ){
                    int num1 = Integer.parseInt(queue.pop());
                    int num2 = Integer.parseInt(queue.pop());
                    int res = num2 / num1;
                    queue.push(String.valueOf(res));
                }else if("+".equals(wd[i]) ){
                    int num1 = Integer.parseInt(queue.pop());
                    int num2 = Integer.parseInt(queue.pop());
                    int res = num1 + num2;
                    queue.push(String.valueOf(res));

                }else if("-".equals(wd[i]) ){
                    int num1 = Integer.parseInt(queue.pop());
                    int num2 = Integer.parseInt(queue.pop());
                    int res = num2 - num1;
                    queue.offer(String.valueOf(res));
                }else{
                    queue.push(wd[i]);
                }
            }
            int res = Integer.parseInt(queue.pop());
            System.out.println(res);
        }
    }

}
